var express = require('express');
var router = express.Router();
var url = require("url");
var md5 = require('md5');

var MongoClient = require("./../mongodb/MongoClient");
var MySql = require("./../mongodb/MySql");



/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send("1");
});

router.get('/login',function (req,res ,next) {
	var loginObj = url.parse(req.url, true).query;
//	console.log(loginObj)
	loginObj.password = md5(loginObj.password);
	MongoClient.mongoConnect('pull', function(db) {
		MySql.findData(db,'users',loginObj,{},function(result){
//			console.log(result)
			if(result.length == "0"){
				res.send("0")
				db.close();
			}else{
				res.send("1");
				db.close();
			}
		})
	},function(err){
		console.log(err);
	})
})
	
module.exports = router;
